
// lib
// config
// script & methods & public
import logUtils from "utils/logUtils";
// store
import { state } from "./state";
// service

import toast from "components/toast";
import { ReqBorrowPage } from "biz/Borrow/api";
import { getBorrowPageService, reportLostService } from "biz/Borrow/service";
// interface
// 其它

// 借阅记录分页列表
export async function getBorrowPage() {
  const sp = state.getSearch();
  logUtils.info("搜索参数", sp);
  const params: ReqBorrowPage = {
    ...sp,
    pageNum: state.page,
    pageSize: state.size,
  };
  // // 调用服务
  state.loading = true;
  const result = await getBorrowPageService(params);
  state.loading = false;
  // 成功
  if (result.payload) {
    state.total = result.payload.total;
    state.list = result.payload.list;
  }
}

// 借阅记录分页列表
export async function getOrderGoodsPage(orderId: string) {
  // const params: ReqOrderGoodsPage = {
  //   orderId,
  //   pageNum: state.orderGoodsPage,
  //   pageSize: state.orderGoodsSize,
  // };
  // // 调用服务
  // state.loading = true;
  // const result = await getOrderGoodsPageService(params);
  // state.loading = false;
  // // 成功
  // if (result.payload) {
  //   state.orderGoodsTotal = result.payload.total;
  //   state.orderGoodsList = result.payload.list;
  // }
}


// 用户报丢
export async function reportLost(id: number) {
  state.loading = true;
  const result = await reportLostService({
    id,
  });
  state.loading = false;
  // 成功
  if (result.payload) {
      state.editModal = false;
      toast.success("报失成功，请到违规管理-丢失管理中支付罚金")
      getBorrowPage()
  }
}

export async function didMount() {
  getBorrowPage();
}
